package com.lyy.document.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyy.common.utils.UUIDUtils;
import com.lyy.document.dao.DocDocumentDao;
import com.lyy.document.pojo.DocDocument;
import com.lyy.document.service.DocDocumentService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 文档内容(DocDocument)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:23:42
 */
@Service
public class DocDocumentServiceImpl extends ServiceImpl<DocDocumentDao, DocDocument> implements DocDocumentService {


    /**
     * 添加文档内容
     *
     * @param docDocument
     */
    @Override
    public void createDocDocument(DocDocument docDocument) {
        docDocument.setCreateDate(new Date());
        baseMapper.insert(docDocument);
    }

    /**
     * 根据主键修改文档内容
     *
     * @param docDocument
     */
    @Override
    public void updateDocDocument(DocDocument docDocument) {
        docDocument.setUpdateDate(new Date());
        baseMapper.update(docDocument, new UpdateWrapper<DocDocument>()
                .eq("id", docDocument.getId())
        );
    }

    /**
     * 根据主键删除文档内容
     *
     * @param id 文档id
     * @return
     */
    @Override
    public void deleteDocDocument(DocDocument docDocument) {
        baseMapper.delete(new UpdateWrapper<DocDocument>()
                .eq("id", docDocument.getId())
        );
    }

    /**
     * 根据主键查询文档内容详情
     *
     * @param id 文档id
     * @return
     */
    @Override
    public DocDocument getDocDocument(DocDocument docDocument) {
        return baseMapper.selectOne(new QueryWrapper<DocDocument>()
                .eq("id", docDocument.getId())
        );
    }

    /**
     * 批量添加文档内容
     *
     * @param docDocuments
     */
    @Override
    public int batchInsert(List<DocDocument> docDocuments) {
        return baseMapper.batchInsert(docDocuments);
    }


    /**
     * 批量修改文档内容
     *
     * @param docDocuments
     */
    @Override
    public int batchUpdate(List<DocDocument> docDocuments) {
        return baseMapper.batchUpdate(docDocuments);
    }

    /**
     * 查询文档内容列表
     *
     * @param docDocument
     */
    @Override
    public List<DocDocument> selectDocDocumentList(DocDocument docDocument) {
        return baseMapper.selectDocDocumentList(docDocument);
    }

    /**
     * 查询文档内容数量
     *
     * @param docDocument
     */
    @Override
    public int selectDocDocumentCount(DocDocument docDocument) {
        return baseMapper.selectDocDocumentCount(docDocument);
    }


    /**
     * 导入文档内容excel
     *
     * @param docDocuments
     */
    @Override
    public List<Map<String, String>> importDocDocumentExcel(List<DocDocument> docDocuments) {
        List<Map<String, String>> mapList = new ArrayList<>();
        docDocuments.forEach(docDocument -> {
            docDocument.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(docDocuments);
        return mapList;
    }
}